/*!
 * 
 * javascript validator 
 * 
 */

function instituteValidation(){
	
	var inst_name = document.getElementById('saveOrUpdateInstitute_institute_name').value;
	var inst_address = document.getElementById('saveOrUpdateInstitute_institute_address').value;
	var inst_phone = document.getElementById('saveOrUpdateInstitute_institute_phoneNumber').value;
	var inst_website = document.getElementById('saveOrUpdateInstitute_institute_website').value;
	var inst_email = document.getElementById('saveOrUpdateInstitute_institute_emailId').value;
	
	//alert("inst_name="+inst_name+"=inst_address="+inst_address+"=inst_phone="+inst_phone+"=inst_website="+inst_website+"=inst_email="+inst_email);
	
	var successFlag = true;
	
	var email_flag =  email_check(inst_email);
	//alert("email_flag=="+email_flag);
	if(!email_flag){
		//document.getElementById("saveOrUpdateInstitute_institute_emailId").setAttribute("class", "error-textboxes");
		successFlag = false;
	}
	/*var phone_flag = phone_no_check(inst_phone);
	alert("phone_flag=="+phone_flag);
	if(!phone_flag){
		successFlag = false;
	}*/
	
	if(inst_address == ""){
		//alert("inst_address==inner"+inst_address); 
		successFlag = false;
	}
	
	var website_flag = website_check(inst_website);
	//alert("website_flag=="+website_flag);
	if(!website_flag){
		successFlag = false;
	}
	
	//alert("success=======Flag=="+successFlag);
	
	if(successFlag){
		document.getElementById("global-custom-message").style.display="none";
		document.getElementById("global-custom-message").innerHTML ="";
		return true;
	}else{
		document.getElementById("global-custom-message").style.display="block";
		document.getElementById("global-custom-message").innerHTML ="Please enter the mandatory fields";
		return false;
	}
	
	
}

function validateImportFile(){
	var screenValue = document.getElementById('importFile_screenName').value;
	var importfile = document.getElementById("importFile_fileUpload").value;
	
	//alert("importfile======="+importfile+"=screenValue="+screenValue);
	
	var successFlag = true;
	
	if(importfile == ""){
		successFlag = false;
	}else{
		var importSplit = importfile.split(".");
		if(importSplit[1] !== "csv"){
			//alert("importSplit[]1="+importSplit[1]);
			successFlag = false;
		}
	}
	
	if(screenValue =="-1" || screenValue ==""){
		successFlag = false;
	}
	
	if(successFlag){
		document.getElementById("global-custom-message").style.display="none";
		document.getElementById("global-custom-message").innerHTML ="";
		return true;
	}else{
		document.getElementById("global-custom-message").style.display="block";
		document.getElementById("global-custom-message").innerHTML ="Please enter the mandatory fields";
		return false;
	}
}

function getScreenValue(){
	var screenValue = document.getElementById('importFile_screenName').value;
	var examName = document.getElementById('import_exam_name').value;
	var	classYear = document.getElementById('import_class_name').value;
	var sectionName = document.getElementById('import_section_name').value;
	var subjectName = document.getElementById('import_subject_name').value;
	location.href = "/downloadFile?method=downloadFileTemplate&screenName="+screenValue+"&examName="+examName+"&classYear="+classYear+"&subjectName="+subjectName+"&sectionName="+sectionName;
}

function showLists(val){
	location.href  = val;
}
function showRespectiveDivs(val){
}

function validateHoliday(){
	alert("validateHoliday=============");
	
}

function validateEvent(){
	alert("validateEvent=============");
}

function validateStaff(){
	alert("validateStaff=============");
}

function validateStudent(){
	alert("validateStudent=============");
}

function validateClass(){
	alert("validateClass=============");
}

function validateExam(){
	alert("validateClass=============");
}

function validateResult(){
	alert("validateClass=============");
}

function validateSection(){
	alert("validateSection=============");
}

function validateSubject(){
	alert("subject=============");
}

/**
 * sms Validation
 */
function validateMultipleNO(){
	alert("validateMultipleNO=============");
}

function validateSmsUpload(){
	alert("validateSmsUpload=============");
}

function validateBroadcast(){
	alert("validateSmsUpload=============");
}


/* Utile Functions */

/*Email validation:*/

function email_check(giv_email){
    var EMAIL_REGEX = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i;
    email_value = EMAIL_REGEX.test(giv_email);
    return email_value;
}

/*Phone Number Validation:*/

function phone_no_check(giv_number){
    var PHONE_REGEX = /^[0-9]+$/;
    phone_value = PHONE_REGEX.test(new String(giv_number));
    return phone_value;
}

/*Website Validation (with out http:)*/

function website_check(giv_website){
    var WEBSITE_REGEX = /^([a-z0-9_-]+\.)*[a-z0-9_-]+(\.[a-z]{2,6}){1,2}$/;
    website_value = WEBSITE_REGEX.test(giv_website);
    return website_value;
}

/*Website validation (with http://)*/

function url_check(giv_url){
    var URL_REGEX = /^(https?|ftp):\/\/.*$/i;
    url_value = URL_REGEX.test(giv_url);
    return url_value;
}

/*Check string and number only(Special character are not allowed)*/

function string_name_and_number_check(giv_name){
	var NAME_REGEX = /^[A-Za-z0-9 ]{3,35}$/;
    website_name_value = NAME_REGEX.test(giv_name);
    return website_name_value;
}

/*Check string only (number’s and special character’s are not alowed)*/

function string_check(giv_str){
    var STRING_REGEX = /^[A-Za-z ]{3,35}$/;
    string_value = STRING_REGEX.test(giv_str);
    return string_value;
}


